#include <fstream>
#include <iostream> 
using namespace std;
 
//ifstream fin ("checker.in");
//ofstream fout ("checker.out");
 
int sum, times, deep;
int n, a;
int y[9];
 
int line (int p)
{
    int sum(0);
    while (p)
    {
        p = p >> 1;
        sum ++;
    }
    return sum;
}
 
void Queue (int l, int r, int row)
{
    int pos(0), p(0);
    if (row != a)
    {
        pos = a & ~(l | r | row);
        while (pos!=0)
        {
            p = pos & (-pos);
            pos -= p;
            y[deep++] = line (p);
            Queue ((l+p)<<1, (r+p)>>1, row + p);
            deep --;
        }
    }
    else
    {
        if (times < 3)
        {
            for (int i=0; i<n-1; ++i)
                cout << y[i] << ' ';
            cout << y[n-1] << endl;
            times ++;
        }
        sum ++;
    }
}
 
int main()
{
    cin >> n;
    a = (1 << n) - 1;
    Queue (0, 0, 0);
    cout << sum << endl;
    system("pause");
    return 0;
}
